package com.yanqu.road.server.cmd.activity.recallplayer;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.connect.CrossAgentLinkedControl;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = CrossProtocol.C_RECALL_PLAYER_BIND, desc = "回归玩家发送请求绑定至跨服,跨服转发到活跃玩家服务器")
public class CrossPlayerRecallBindCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception{
        RecallPlayerProto.WriteRecallCodeServerReqCrossMsg reqCrossMsg = RecallPlayerProto.WriteRecallCodeServerReqCrossMsg.parseFrom(packet.getBytes());
        RecallPlayerProto.WriteRecallCodeCrossReqServerMsg.Builder crossReqServerMsg = RecallPlayerProto.WriteRecallCodeCrossReqServerMsg.newBuilder();
        crossReqServerMsg.setReqCrossMsg(reqCrossMsg);
        crossReqServerMsg.setOriServerId(CrossAgentLinkedControl.getLinkedClient(ctx).getServerId());
        crossReqServerMsg.setOriUserId(packet.getPlayerId());

        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_RECALL_PLAYER_CROSS_BIND, crossReqServerMsg);
        MessageHelper.sendPacket(reqCrossMsg.getReqBindServerId(), 0, message);
    }
}
